package com.example.itces.service.Impl;

import com.example.itces.domain.User;
import com.example.itces.mapper.UserMapper;
import com.example.itces.service.UserService;
import com.example.itces.utils.MD5utils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Resource
    UserMapper userMapper;


    @Override
    public User findByUsername(String username) {
        return userMapper.findByUsername(username);
    }

    @Override
    public int UserRegister(User user) {
        //md5加密
        String password = MD5utils.MD5(user.getName(), user.getPassword());
        user.setPassword(password);
        int i = userMapper.UserRegister(user);
        return i;
    }

    @Override
    public Boolean selectByName(String username) {
        Boolean aBoolean = userMapper.selectByName(username);
        return aBoolean ;
    }

    @Override
    public PageInfo<User> getAllUser(int pageNum,int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<User> list=userMapper.getAllUser();
        PageInfo<User> pageInfo=new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public Boolean delUserById(int id) {
        return userMapper.delUserById(id);
    }

    @Override
    public Boolean updateUserById(User user) {
        return userMapper.updateUserById(user);
    }

    @Override
    public Boolean addUser(User user) {
        return userMapper.addUser(user);
    }

}
